const { ccclass, property } = cc._decorator;

@ccclass
export default class awaitBtn extends cc.Component {

    @property(cc.Label)
    info: cc.Label = null;

    @property(cc.Integer)
    time: number = 30;

    @property(cc.Button)
    button: cc.Button = null;

    tempTime: number;

    protected onLoad(): void {
        this.info.node.on(cc.Node.EventType.MOUSE_DOWN, () => {
            this.tempTime = 1;
        })

        let event = new cc.Component.EventHandler();
        event.target = this.node;
        event.component = "awaitBtn";
        event.handler = "onClick";
        this.button.clickEvents.push(event)
    }

    protected onEnable(): void {
        // this.time = 5;
        this.tempTime = this.time;
        this.button.interactable = false;
    }

    onClick() {
        this.tempTime = this.time;
        this.button.interactable = false;
        this.info.node.active = true;
    }

    protected update(dt: number): void {
        if (this.tempTime > 0) {
            this.info.node.active = true;
            this.tempTime -= dt;
            this.info.string = "等待" + Math.floor(this.tempTime) + "秒后"
        } else {
            this.info.node.active = false;
            this.button.interactable = true;
        }
    }
}
